package com.gexiaobao.pigeon.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import com.gexiaobao.pigeon.R

/**
 * @author:hxw
 * @date  :2022/12/8
 * @desc  :
 */
class RxDialogApplyPayAuction(context: Context?) : RxDialog(context!!) {

    private lateinit var cancelView: AppCompatTextView
    private lateinit var sureView: AppCompatTextView
    private lateinit var llUserMargin: LinearLayout
    private lateinit var llNoUserMargin: LinearLayout
    private lateinit var tvNoUseMargin: AppCompatTextView
    private lateinit var tvUseMargin: AppCompatTextView
    private lateinit var tvMarginBalance: AppCompatTextView
    private lateinit var ivMarginUse: AppCompatImageView
    private lateinit var ivMarginUnUse: AppCompatImageView

    private var isUseMargin = false

    init {
        initView()
    }

    @SuppressLint("MissingInflatedId")
    private fun initView() {
        val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_apply_pay_auction, null)
        cancelView = dialogView.findViewById(R.id.tvCancel)
        sureView = dialogView.findViewById(R.id.tvSure)
        llUserMargin = dialogView.findViewById(R.id.llUserMargin)
        llNoUserMargin = dialogView.findViewById(R.id.llNoUserMargin)
        tvUseMargin = dialogView.findViewById(R.id.tvUseMargin)
        tvNoUseMargin = dialogView.findViewById(R.id.tvNoUseMargin)
        ivMarginUse = dialogView.findViewById(R.id.ivDialogMarginUse)
        ivMarginUnUse = dialogView.findViewById(R.id.ivDialogMarginUnUse)
        tvMarginBalance = dialogView.findViewById(R.id.tvMarginBalance)

        llNoUserMargin.isSelected = true

        cancelView.setOnClickListener {
            dismiss()
        }
        llUserMargin.setOnClickListener {
            isUseMargin = true
            ivMarginUse.setImageDrawable(ContextCompat.getDrawable(context,R.mipmap.icon_margin_use))
            ivMarginUnUse.setImageDrawable(ContextCompat.getDrawable(context,R.mipmap.icon_margin_unuse))
            llNoUserMargin.isSelected = false
            llUserMargin.isSelected = true
            tvUseMargin.setTextColor(ContextCompat.getColor(context, R.color.white))
            tvNoUseMargin.setTextColor(ContextCompat.getColor(context, R.color.comm_text_gray_light))
        }
        llNoUserMargin.setOnClickListener {
            isUseMargin = false
            ivMarginUse.setImageDrawable(ContextCompat.getDrawable(context,R.mipmap.icon_margin_unuse))
            ivMarginUnUse.setImageDrawable(ContextCompat.getDrawable(context,R.mipmap.icon_margin_use))
            llNoUserMargin.isSelected = true
            llUserMargin.isSelected = false
            tvUseMargin.setTextColor(ContextCompat.getColor(context, R.color.comm_text_gray_light))
            tvNoUseMargin.setTextColor(ContextCompat.getColor(context, R.color.white))
        }
        setContentView(dialogView)
    }

    fun setMarginBalance(balance: String) {
        tvMarginBalance.text = balance
    }

    fun getIsUseMargin(): Boolean {
        return isUseMargin
    }

    fun setSureListener(listener: View.OnClickListener?) {
        sureView.setOnClickListener(listener)
    }

    fun setCancelListener(listener: View.OnClickListener?) {
        cancelView.setOnClickListener(listener)
    }

    fun setLeftBtnContent(textLeft: String) {
        if (textLeft.isEmpty()) {
            return
        }
        cancelView.text = textLeft
    }

    fun setRightBtnContent(textRight: String) {
        if (textRight.isEmpty()) {
            return
        }
        sureView.text = textRight
    }

    fun setRightBtnContentColor(color: Int) {
        sureView.setTextColor(color)
    }

    fun setLeftBtnContentColor(color: Int) {
        cancelView.setTextColor(color)
    }
}